import _ from 'lodash';
import { EventEmitter } from 'events';
interface EventBus {
  subscribe(eventName: string, listener: (...args: any[]) => void);
  subscribeOnce(event: string, listener: (...args: any[]) => void);
  publish(eventName: string, ...args: any[]);
  getName(): string;
}
class MemoryEventBus implements EventBus {
  private eventEmitter: EventEmitter;
  constructor(private name: string) {
    this.eventEmitter = new EventEmitter();
  }
  subscribe(eventName: string, listener: (...args: any[]) => void) {
    this.eventEmitter.addListener(eventName, listener);
  }
  subscribeOnce(eventName: string, listener: (...args: any[]) => void) {
    this.eventEmitter.once(eventName, listener);
  }
  publish(eventName: string, ...args: any[]) {
    this.eventEmitter.emit(eventName, ...args);
  }
  getName() {
    return this.name;
  }
}
export class GlobalBuses {
  static DriverEvent: EventBus = new MemoryEventBus('Driver:EventBus');
  static AgentEvent: EventBus = new MemoryEventBus('Agent:EventBus');
}